package com.gaia.member.gaiatt.login;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.gaia.member.gaiatt.R;
import com.gaia.member.gaiatt.utils.Uiutils;
import com.gaia.member.gaiatt.utils.ZhtUtils;

import butterknife.Bind;
import butterknife.ButterKnife;

public class LoginActivity extends AppCompatActivity {


    @Bind(R.id.et_phone)
    EditText etPhone;
    @Bind(R.id.et_password)
    EditText etPassword;
    @Bind(R.id.btn_login)
    Button btnLogin;
    @Bind(R.id.tv_regist_new)
    TextView tvRegistNew;
    @Bind(R.id.tv_forget_password)
    TextView tvForgetPassword;
    @Bind(R.id.tv_title_title_bar)
    TextView tvTitleToolBar;
    private Activity mContext;
    private String phone;
    private String password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        mContext = this;
        ButterKnife.bind(this);

        initView();
    }

    private void initView() {
        tvTitleToolBar.setText("登录");
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                phone = etPhone.getText().toString().trim();
                password = etPassword.getText().toString().trim();
                if (TextUtils.isEmpty(phone)) {
                    Uiutils.showToast(mContext, "请输入手机号");
                } else {
                    if (TextUtils.isEmpty(password)) {
                        Uiutils.showToast(mContext, "请输入密码");
                    } else {
                        isPhonePasswordValid(phone, password);
                    }
                }
            }
        });

        tvRegistNew.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ZhtUtils.gotoIntent(mContext, RegistWelcomeActivity.class);
            }
        });

        tvForgetPassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ZhtUtils.gotoIntent(mContext, FindPasswordActivity.class);
            }
        });
    }

    /**
     * 验证输入的用户名和密码是否有效
     *
     * @param phone
     * @param password
     */
    private void isPhonePasswordValid(String phone, String password) {
        Uiutils.showToast(mContext, "正在登录……");
    }


}
